package com.controller.supply;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.DateUtils;
import com.common.http.HttpResult;
import com.model.purchase.CompeteVoModel;
import com.model.purchase.SupplyCompeteModel;
import com.service.supply.SupplyCompeteService;

/**
 * 
 */
@Controller("supplyCompeteController")
@RequestMapping(value = "/api")
public class CompeteController {
	static final Logger logger = LoggerFactory.getLogger(CompeteController.class);

	@Autowired
	SupplyCompeteService supplyCompeteService;

	/**
	 * 查询列表
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "supply/compete/selectList", method = { RequestMethod.POST })
	@ResponseBody
	public HttpResult selectList(@RequestParam Map<String, Object> map) {
		return supplyCompeteService.selectList(map);
	}

	/**
	 * 查询详情
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "supply/compete/selectInfo", method = { RequestMethod.GET })
	@ResponseBody
	public HttpResult selectInfor(@RequestParam String inqId) {
		return supplyCompeteService.selectInfor(inqId);
	}

	@RequestMapping(value = "supply/compete/selectRank", method = { RequestMethod.GET })
	@ResponseBody
	public HttpResult selectRank(@RequestParam String inqId) {
		return supplyCompeteService.selectRank(inqId);
	}

	/**
	 * 保存
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "supply/compete/save", method = { RequestMethod.POST })
	@ResponseBody
	public HttpResult save(@RequestBody CompeteVoModel supplyCompeteModel) {
		return supplyCompeteService.save(supplyCompeteModel);
	}

	/**
	 * 提交
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "supply/compete/commit", method = { RequestMethod.POST })
	@ResponseBody
	public HttpResult commit(@RequestBody CompeteVoModel supplyCompeteModel) {
		return supplyCompeteService.commit(supplyCompeteModel);
	}

	@RequestMapping(value = "supply/compete/finish", method = { RequestMethod.POST })
	@ResponseBody
	public HttpResult finish(@RequestBody SupplyCompeteModel supplyCompeteModel) {
		return supplyCompeteService.finish(supplyCompeteModel);
	}

	/**
	 * 删除
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "supply/compete/delete", method = { RequestMethod.DELETE })
	@ResponseBody
	public HttpResult delete(@RequestParam String infId, @RequestParam String inqId) {
		return supplyCompeteService.delete(infId, inqId);
	}

	/**
	 * 跟进最低价
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "supply/compete/back", method = { RequestMethod.GET })
	@ResponseBody
	public HttpResult back(@RequestParam String inqId) {
		return supplyCompeteService.back(inqId);
	}

	/**
	 * 撤回
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "supply/compete/updataLowStatus", method = { RequestMethod.GET })
	@ResponseBody
	public HttpResult updataLowStatus(@RequestParam String inqId, @RequestParam String planId) {
		return supplyCompeteService.updataLowStatus(inqId, planId);
	}

	/**
	 * 导出
	 * 
	 * @param map
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(value = "supply/compete/export")
	public void export(@RequestParam Map<String, Object> map, HttpServletResponse response) throws IOException {
		response.setContentType("application/vnd.ms-excel");
		response.setCharacterEncoding("utf-8");
		String fileName = URLEncoder.encode("采购订单-" + DateUtils.getCurrentDate(), "UTF-8");
		response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
		supplyCompeteService.export(map, response);

	}
}
